# this works if (docroot)/{{ mediawiki_symlink }} links to install
# and LocalSettings.php has
# $wgScriptPath = "/{{ mediawiki_symlink }}";
# $wgArticlePath = "/wiki/$1";
# $wgUsePathInfo = true;

location ~ ^/{{ mediawiki_symlink }}/(index|load|api|thumb|opensearch_desc)\.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass php; # or whatever port your PHP-FPM listens on
}

# Images
location /{{ mediawiki_symlink }}/images {
    # Separate location for images/ so .php execution won't apply
}

location /{{ mediawiki_symlink }}/images/deleted {
    # Deny access to deleted images folder
    deny all;
}

# MediaWiki assets (usually images)
location ~ ^/{{ mediawiki_symlink }}/resources/(assets|lib|src) {
    try_files $uri 404;
    add_header Cache-Control "public";
    expires 7d;
}

# Assets, scripts and styles from skins and extensions
location ~ ^/{{ mediawiki_symlink }}/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|ttf|woff|woff2)$ {
    try_files $uri 404;
    add_header Cache-Control "public";
    expires 7d;
}

## Uncomment the following code if you wish to use the installer/updater
## installer/updater
#location /{{ mediawiki_symlink }}/mw-config/ {
#    # Do this inside of a location so it can be negated
#    location ~ \.php$ {
#        include /etc/nginx/fastcgi_params;
#        fastcgi_param SCRIPT_FILENAME $document_root/{{ mediawiki_symlink }}/mw-config/$fastcgi_script_name;
#        fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
#    }
#}

# Handling for the article path (pretty URLs)
location {{ mediawiki_url }}/ {
    rewrite ^{{ mediawiki_url }}/(?<pagename>.*)$ /{{ mediawiki_symlink }}/index.php;
}

# Explicit access to the root website, redirect to main page (adapt as needed)
location = {{ mediawiki_url }} {
    return 301 {{ mediawiki_url }}/Main_Page;
}

# http://box/mediawiki* redirect to http://box/wiki/Main_Page
location {{ mediawiki_url2 }} {
    return 301 {{ mediawiki_url }}/Main_Page;
}
